package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AProcessRoute;
import com.ruoyi.system.service.IAProcessRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工艺路线Controller
 * 
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/system/processroute")
public class AProcessRouteController extends BaseController
{
    @Autowired
    private IAProcessRouteService aProcessRouteService;

    /**
     * 查询工艺路线列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AProcessRoute aProcessRoute)
    {
        startPage();
        List<AProcessRoute> list = aProcessRouteService.selectAProcessRouteList(aProcessRoute);
        return getDataTable(list);
    }

    @GetMapping("/listRoute")
    public TableDataInfo listRoute(AProcessRoute aProcessRoute)
    {
        startPage();
        aProcessRoute.setStepSort(1L);
        List<AProcessRoute> list = aProcessRouteService.selectAProcessRouteList(aProcessRoute);
        return getDataTable(list);
    }

    /**
     * 导出工艺路线列表
     */
    @Log(title = "工艺路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AProcessRoute aProcessRoute)
    {
        List<AProcessRoute> list = aProcessRouteService.selectAProcessRouteList(aProcessRoute);
        ExcelUtil<AProcessRoute> util = new ExcelUtil<AProcessRoute>(AProcessRoute.class);
        util.exportExcel(response, list, "工艺路线数据");
    }

    /**
     * 获取工艺路线详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aProcessRouteService.selectAProcessRouteById(id));
    }

    /**
     * 新增工艺路线
     */
    @Log(title = "工艺路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<AProcessRoute> aProcessRouteList)
    {
        return toAjax(aProcessRouteService.insertAProcessRoute(aProcessRouteList));
    }

    /**
     * 修改工艺路线
     */
    @Log(title = "工艺路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<AProcessRoute> aProcessRouteList)
    {
        return toAjax(aProcessRouteService.updateAProcessRoute(aProcessRouteList));
    }

    /**
     * 删除工艺路线
     */
    @Log(title = "工艺路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aProcessRouteService.deleteAProcessRouteByIds(ids));
    }

    @Log(title = "工艺路线", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeByRouteId/{routeId}")
    public AjaxResult removeByRouteId(@PathVariable String routeId)
    {
        return toAjax(aProcessRouteService.deleteAProcessRouteByRouteId(routeId));
    }
}
